package com.cskaoyan.service;

import com.cskaoyan.mapper.MarketCommentMapper;
import com.cskaoyan.model.MarketComment;
import com.cskaoyan.model.MarketCommentExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author zoe ling
 * @Date 2024/6/11
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    MarketCommentMapper commentMapper;


    @Override
    public Map<String, Object> findById(Integer valueId, byte valueType, int page, int limit) {
        MarketCommentExample example = new MarketCommentExample();
        example.createCriteria()
                .andTypeEqualTo(valueType)
                .andValueIdEqualTo(valueId)
                .andDeletedEqualTo(false);
        PageHelper.startPage(page,limit);
        List<MarketComment> data = commentMapper.selectByExample(example);
        PageInfo<MarketComment> pageInfo = new PageInfo<>(data);
        long count = pageInfo.getTotal();
        Map<String,Object> commentMap=new HashMap<>();
        commentMap.put("count",count);
        commentMap.put("data",data);
        return commentMap;
    }
}
